package org.onion.pattern.event.outbox.data;

import lombok.Data;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import java.time.LocalDateTime;
import java.util.Map;

/**
 * 内部事件信息
 */
@Data
public class OutboxEventInfo {

    public static final String NONE_GROUP = "none";

    private Long                id;
    private String              eventKey;
    private OutboxEventStatus   outBoxEventStatus;
    private Long       eventTime;
    private byte[]              payload;
    private String              domainId;
    private String              domainType;
    private String              serializer;
    //事件外部化字段
    private String              channel;
    private Map<String, String> props;
    private String              topic;
    private String              subTopic;
    //版本号
    private Long                ver;
    private LocalDateTime       publishTime;
    private LocalDateTime       createTime;
    //分组
    private String              group;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || getClass() != o.getClass()) return false;

        OutboxEventInfo that = (OutboxEventInfo) o;

        return new EqualsBuilder().append(eventKey, that.eventKey).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37).append(eventKey).toHashCode();
    }
}
